home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / doModifyConstraintAxes.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.8 KB  |  157 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Sept, 2002
  22. //  Author:         bb
  23. //
  24. //    Procedure Name:
  25. //        doModifyConstraintAxes
  26. //
  27. //    Description:
  28. //      The user selects the constrained object.
  29. //        This script restricts the axes affected by the constraint.
  30. //
  31. //    Input Arguments:
  32. //    $version: The version of this option box.  Used to know how to 
  33. //    interpret the $args array.
  34. //        "1" : first verison of nla
  35. //  
  36. //    $args
  37. //    Version 1
  38. //    [0]        $constrainX :  whether or not to constrain x
  39. //    [1]        $constrainY :  whether or not to constrain y
  40. //    [2]        $constrainY :  whether or not to constrain z
  41. //  [3]     $maintainOffset: whether to maintain the existing offset to the remaining targets
  42. //
  43. //    Return Value:
  44. //        none
  45. //
  46.  
  47.  
  48. global proc
  49. doModifyConstraintAxes( string $version, string $args[] )
  50. {
  51.     string $sels[] = `ls -sl`;
  52.     if (size($sels) == 0) {
  53.         error("You must select the constrained object.");
  54.         return;
  55.     }
  56.  
  57.     string $cmd;
  58.     int $constrainX = $args[0];
  59.     int $constrainY = $args[1];
  60.     int $constrainZ = $args[2];
  61.     int $maintainOffset = $args[3];
  62.  
  63.     string $flags = " -e";
  64.     string $parentFlags = " -e";    
  65.     if (! $constrainX) {
  66.         $flags += " -skip x";
  67.         $parentFlags += " -skipRotate x -skipTranslate x";
  68.     }
  69.     if (! $constrainY) {
  70.         $flags += " -skip y";
  71.         $parentFlags += " -skipRotate y -skipTranslate y";        
  72.     }
  73.     if (! $constrainZ) {
  74.         $flags += " -skip z";
  75.         $parentFlags += " -skipRotate z -skipTranslate z";
  76.     }
  77.     if ($flags == " -e") {
  78.         $flags += " -skip none";
  79.         $parentFlags += " -skipRotate none -skipTranslate none";
  80.     }
  81.  
  82.     if (0 == ($constrainX + $constrainY + $constrainZ)) {
  83.         error("No axes were selected.");
  84.         return;
  85.     }
  86.     
  87.     if ($maintainOffset) {
  88.         $flags += " -maintainOffset; ";
  89.         $parentFlags += " -maintainOffset; ";        
  90.     } else {
  91.         // Reset the offset of the constraint back to 0 0 0 if maintainOffset
  92.         // is turned off.
  93.         //
  94.         $flags += " -offset 0 0 0; ";
  95.         $parentFlags += "; ";
  96.     }
  97.  
  98.     for ($constrainedObj in $sels) {
  99.         string $p1 = `pointConstraint -q $constrainedObj`;
  100.         if (size($p1)) {
  101.             $cmd += "pointConstraint"+$flags;
  102.         }
  103.         string $a1 = `aimConstraint -q $constrainedObj`;
  104.         if (size($a1)) {
  105.             $cmd += "aimConstraint"+$flags;
  106.         }
  107.         string $o1 = `orientConstraint -q $constrainedObj`;
  108.         if (size($o1)) {
  109.             $cmd += "orientConstraint"+$flags;
  110.         }
  111.         string $s1 = `scaleConstraint -q $constrainedObj`;
  112.         if (size($s1)) {
  113.             $cmd += "scaleConstraint"+$flags;
  114.         }
  115.         string $p2 = `parentConstraint -q $constrainedObj`;
  116.         if (size($p2)) {
  117.             $cmd += "parentConstraint"+$parentFlags;
  118.             // Get the parent constraint from the constrained object
  119.             //
  120.             string $constrainedRelatives[] = 
  121.                 `listRelatives -type "parentConstraint" $constrainedObj`;
  122.             if ( !$maintainOffset && `size $constrainedRelatives` == 1 )
  123.             {
  124.                 // If maintainOffset is not specified reset the offsets on the
  125.                 // constraint node.  If there is not exactly 1 parent 
  126.                 // constraint then don't attempt to set the offsets to 0 0 0.
  127.                 //
  128.  
  129.                 $parentConstraint = $constrainedRelatives[ 0 ];
  130.  
  131.                 // Get the name of each targetOffsetRotate and 
  132.                 // targetOffsetTranslate attribute on the constraint node.
  133.                 // 
  134.                 $cmd += "string $parentConstraintOffsetAttrs[] = ";
  135.                 $cmd += "    `listAttr -st \"targetOffsetTranslate\" ";
  136.                 $cmd += "              -st \"toffsetRotate\" ";
  137.                 $cmd += ( "              -m \""+$parentConstraint+".target\"`;");
  138.  
  139.                 $cmd += "string $offsetAttr; ";
  140.  
  141.                 // Set each targetOffset attribute on the node to 0 0 0.
  142.                 // This ensures that if the user 
  143.                 //
  144.                 $cmd += "for ( $offsetAttr in $parentConstraintOffsetAttrs ) ";
  145.                 $cmd += "{";
  146.                 $cmd += ("setAttr (\""+ $parentConstraint +".\"+$offsetAttr)");
  147.                 $cmd += "           0 0 0;";
  148.                 $cmd += "}";
  149.             }
  150.         }
  151.     }
  152.     if (size($cmd) == 0) {
  153.         error("An aim-, orient-, parent-, point-, or scale-constrained object must be the last object selected.");
  154.     }
  155.     evalEcho $cmd;
  156. }
  157.